// JavaScript Document
//图片向左滚动
(function($){

	$.fn.kxbdMarquee = function(options){
		var opts = $.extend({},$.fn.kxbdMarquee.defaults, options);
		
		return this.each(function(){
			var $marquee = $(this);//滚动元素容器
			var _scrollObj = $marquee.get(0);//滚动元素容器DOM
			var scrollW = $marquee.width();//滚动元素容器的宽度
			var scrollH = $marquee.height();//滚动元素容器的高度
			var $element = $marquee.children(); //滚动元素
			var $kids = $element.children();//滚动子元素
			var scrollSize=0;//滚动元素尺寸
			var _type = (opts.direction == 'left' || opts.direction == 'right') ? 1:0;//滚动类型，1左右，0上下

			//防止滚动子元素比滚动元素宽而取不到实际滚动子元素宽度
			$element.css(_type?'width':'height',10000);
			//获取滚动元素的尺寸
			if (opts.isEqual) {
				scrollSize = $kids[_type?'outerWidth':'outerHeight']() * $kids.length;
			}else{
				$kids.each(function(){
					scrollSize += $(this)[_type?'outerWidth':'outerHeight']();
				});
			}
			//滚动元素总尺寸小于容器尺寸，不滚动
			if (scrollSize<(_type?scrollW:scrollH)) return; 
			//克隆滚动子元素将其插入到滚动元素后，并设定滚动元素宽度
			$element.append($kids.clone()).css(_type?'width':'height',scrollSize*2);
			
			var numMoved = 0;
			function scrollFunc(){
				var _dir = (opts.direction == 'left' || opts.direction == 'right') ? 'scrollLeft':'scrollTop';
				if (opts.loop > 0) {
					numMoved+=opts.scrollAmount;
					if(numMoved>scrollSize*opts.loop){
						_scrollObj[_dir] = 0;
						return clearInterval(moveId);
					} 
				}
				if(opts.direction == 'left' || opts.direction == 'up'){
					var newPos = _scrollObj[_dir] + opts.scrollAmount;
					if(newPos>=scrollSize){
						newPos -= scrollSize;
					}
					_scrollObj[_dir] = newPos;
				}else{
					var newPos = _scrollObj[_dir] - opts.scrollAmount;
					if(newPos<=0){
						newPos += scrollSize;
					}
					_scrollObj[_dir] = newPos;
				}
			};
			//滚动开始
			var moveId = setInterval(scrollFunc, opts.scrollDelay);
			//鼠标划过停止滚动
			$marquee.hover(
				function(){
					clearInterval(moveId);
				},
				function(){
					clearInterval(moveId);
					moveId = setInterval(scrollFunc, opts.scrollDelay);
				}
			);
			
			//控制加速运动
			if(opts.controlBtn){
				$.each(opts.controlBtn, function(i,val){
					$(val).bind(opts.eventA,function(){
						opts.direction = i;
						opts.oldAmount = opts.scrollAmount;
						opts.scrollAmount = opts.newAmount;
					}).bind(opts.eventB,function(){
						opts.scrollAmount = opts.oldAmount;
					});
				});
			}
		});
	};
	$.fn.kxbdMarquee.defaults = {
		isEqual:true,//所有滚动的元素长宽是否相等,true,false
		loop: 0,//循环滚动次数，0时无限
		direction: 'left',//滚动方向，'left','right','up','down'
		scrollAmount:1,//步长
		scrollDelay:10,//时长
		newAmount:3,//加速滚动的步长
		eventA:'mousedown',//鼠标事件，加速
		eventB:'mouseup'//鼠标事件，原速
	};
	
	$.fn.kxbdMarquee.setDefaults = function(settings) {
		$.extend( $.fn.kxbdMarquee.defaults, settings );
	};
	
})(jQuery);
$(document).ready(function(){
	$('.marquee').kxbdMarquee({
			direction:'left',
			eventA:'mouseenter',
			eventB:'mouseleave'
	});
});
//向上滚动
(function($){   
$.fn.extend({   
        Scroll:function(opt,callback){   
                //参数初始化   
                if(!opt) var opt={};   
                var _btnUp = $("#"+ opt.up);//Shawphy:向上按钮   
                var _btnDown = $("#"+ opt.down);//Shawphy:向下按钮   
                var timerID;   
                var _this=this.eq(0).find("ul:first");   
                var     lineH=_this.find("li:first").height(), //获取行高   
                        line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数，默认为一屏，即父容器高度   
                        speed=opt.speed?parseInt(opt.speed,10):1000; //卷动速度，数值越大，速度越慢（毫秒）   
                        timer=opt.timer //?parseInt(opt.timer,10):3000; //滚动的时间间隔（毫秒）   
                if(line==0) line=1;   
                var upHeight=0-line*lineH;   
                //滚动函数   
                var scrollUp=function(){   
                        _btnUp.unbind("click",scrollUp); //Shawphy:取消向上按钮的函数绑定   
                        _this.animate({   
                                marginTop:upHeight   
                        },speed,function(){   
                                for(i=1;i<=line;i++){   
                                        _this.find("li:first").appendTo(_this);   
                                }   
                                _this.css({marginTop:0});   
                                _btnUp.bind("click",scrollUp); //Shawphy:绑定向上按钮的点击事件   
                        });   
  
                }   
                //Shawphy:向下翻页函数   
                var scrollDown=function(){   
                        _btnDown.unbind("click",scrollDown);   
                        for(i=1;i<=line;i++){   
                                _this.find("li:last").show().prependTo(_this);   
                        }   
                        _this.css({marginTop:upHeight});   
                        _this.animate({   
                                marginTop:0   
                        },speed,function(){   
                                _btnDown.bind("click",scrollDown);   
                        });   
                }   
               //Shawphy:自动播放   
                var autoPlay = function(){   
                        if(timer)timerID = window.setInterval(scrollUp,timer);   
                };   
                var autoStop = function(){   
                        if(timer)window.clearInterval(timerID);   
                };   
                 //鼠标事件绑定   
                _this.hover(autoStop,autoPlay).mouseout();   
                _btnUp.css("cursor","pointer").click( scrollUp ).hover(autoStop,autoPlay);//Shawphy:向上向下鼠标事件绑定   
                _btnDown.css("cursor","pointer").click( scrollDown ).hover(autoStop,autoPlay);   
  
        }         
})   
})(jQuery);   
  
$(document).ready(function(){   
        $("#scrollDiv").Scroll({line:1,timer:2000});   
});   
//普通用户和家政用户登录切换
 function cput1(dl){
	for(i=1;i<=2;i++){
		if(i==dl){
		document.getElementById(dl).style.display="block";
	}else{
		document.getElementById(i).style.display="none";
	 }
	}
}
//公司右下脚广告幻灯片
var num = 1;
function changePic(){
	for(var i=1;i<=4;i++){
	 if(num==i)
	 	document.getElementById("div"+i).style.display="block";
	 else
	 	document.getElementById("div"+i).style.display="none";
	}
	num++;
	if(num>4)
		num=1;
	setTimeout("changePic()",2000);
}
//公司左下脚广告幻灯片
var num = 5;
function f_chagePic(){
	for(var i=5;i<=7;i++){
	 if(num==i)
	 	document.getElementById("pic"+i).style.display="block";
	 else
	 	document.getElementById("pic"+i).style.display="none";
	}
	num++;
	if(num>7)
		num=5;
	setTimeout("f_pic()",2000);
}

